import { Button, Toast } from "antd-mobile";
import axios from "axios";
import React, { Component } from "react";
import Header from "../../components/Header/Header";
import {  reqcartadd, reqgetgoodsinfo } from "../../http/api";

export default class Detail extends Component {
  constructor() {
    super();
    this.state = {
      info: {},
    };
  }
  async componentDidMount() {
    let res = await reqgetgoodsinfo( {id:this.props.match.params.id} );
    this.setState({
      info:res.data.list[0]
    })
  }
  //加入购物车
 async addShop(){
  let res=await reqcartadd({
    uid:JSON.parse(sessionStorage.getItem("userInfo")).uid,
    goodsid:this.props.match.params.id,
    num:1, 
  })
  if(res.data.code===200){
    Toast.show({
      content:res.data.msg
    })
  }



  }
  render() {
    let {info}=this.state
    return (
      <div>
        <Header title="商品详情" back></Header>
        <div dangerouslySetInnerHTML={{ __html: info.description }}></div>
        <Button color="primary" onClick={()=>this.addShop()}>加入购物车</Button>
      </div>
    );
  }
}
